$(function () {
    //常用jQuery对象
    var lesson_datagrid = $("#lesson_list");

    //==========================================================================
    //封装方法
    var methodObj = {

        //刷新页面
        reloadList: function () {
            $("#keyword").textbox("setValue", "");
            $("#deptId").combobox("setValue", "");
            var beginDate = $("#beginDate").datebox("setValue", "");
            var endDate = $("#endDate").datebox("setValue", "");
            lesson_datagrid.datagrid("reload", {deptId: "-1"});
        },


        //高级查询按钮
        searchs: function () {
            var classId = $("#classId").textbox("getValue");
            var classroomId = $("#classroomId").combobox("getValue");
            var teacherId = $("#teacherId").combobox("getValue");
            var beginDate = $("#beginDate").datebox("getValue");
            var endDate = $("#endDate").datebox("getValue");
            lesson_datagrid.datagrid("load", {
                classId: classId,
                classroomId: classroomId,
                teacherId: teacherId,
                beginDate: beginDate,
                endDate: endDate
            });
        },
    }


    //==========================================================================================
    //按钮绑定事件
    $("[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd]();
    });

    //页面数据加载
    lesson_datagrid.datagrid({
        fit: true,
        fitColumns: true,
        url: "/lesson/query.do",
        singleSelect: "true",
        pagination: true,
        rownumbers: true,
                columns: [[
            {field: 'lessonDate', title: '日期', width: 100},
            {
                field: 'clz', title: '班级', width: 100,formatter: function (clz) {
                    return clz ? clz.name: "<font color='red'>未分配</font>";
                }
            },
            {field: 'name', title: '课程名称', width: 100},
            {field: 'classManager', title: '班主任', width: 100, formatter: function (classManager) {
                    return classManager ? classManager.username : "<font color='red'>未分配</font>";
                }
            },
            {field: 'teacher', title: '任课教师', width: 100, formatter: function (teacher) {
                    return teacher ? teacher.username : "<font color='red'>未分配</font>";
                }
            },
            {field: 'classroom', title: '教室', width: 100, formatter: function (classroom) {
                    return classroom ? classroom.name : "<font color='red'>未分配</font>";
                }
             },
            {field: 'sign', title: '备注', width: 100},
            // {field: 'sate', title: '状态', width: 100},

        ]],
        toolbar: "#tools"
    });

    /*日历显示*/
    $('#cc').calendar({
        current:new Date(),
        onSelect: function(date){
            var classId = $("#classId").textbox("getValue");
            var classroomId = $("#classroomId").combobox("getValue");
            var teacherId = $("#teacherId").combobox("getValue");
            var beginDate = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
            var endDate = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();

            lesson_datagrid.datagrid("load", {
                classId: classId,
                classroomId: classroomId,
                teacherId: teacherId,
                beginDate: beginDate,
                endDate: endDate
            });
        }
    });

    /*日历下面的东东*/

});

